import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types';
import { getWeekMonthQuarterYear } from '/@/utils';
import { filterDictTextByCache, filterDictText } from '/@/utils/dict/JDictSelectUtil';
import { defHttp } from '/@/utils/http/axios';
import { h } from 'vue';
import { Avatar, Tag, Tooltip, Image } from 'ant-design-vue';
//引入依赖
import { useForm, BasicForm } from '/@/components/Form';

//列表数据
export const columns: BasicColumn[] = [
  {
    title: '商品主图',
    align: 'center',
    dataIndex: 'mainPic',
    slots: { customRender: 'img' },
    //customRender: render.renderImage,
    width: 150,
  },
  {
    title: '商品描述',
    align: 'center',
    dataIndex: 'productName',
  },
  {
    title: '商品UPC条码',
    align: 'center',
    dataIndex: 'upcCode',
  },
  {
    title: '其他条码',
    align: 'center',
    dataIndex: 'otherCode',
  },
  {
    title: '覆盖渠道',
    align: 'center',
    dataIndex: 'coverCustomer',
  },
  {
    title: '商品品牌',
    align: 'center',
    dataIndex: 'brand',
    width: 80,
  },
  {
    title: '一级类目',
    align: 'center',
    dataIndex: 'l1Type',
    width: 80,
  },
  {
    title: '二级类目',
    align: 'center',
    dataIndex: 'l2Type',
    width: 80,
  },
  {
    title: '箱规',
    align: 'center',
    dataIndex: 'cartonSpec',
    width: 80,
  },
  {
    title: '产品规格',
    align: 'center',
    dataIndex: 'productSpec',
    width: 100,
  },
  {
    title: '重量/KG',
    align: 'center',
    dataIndex: 'weight',
    width: 100,
  },
  {
    title: '进货单价/元',
    align: 'center',
    dataIndex: 'purchasePrice',
    width: 100,
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '商品UPC条码',
    field: 'upcCode',
    component: 'JInput', //
  },
  {
    label: '商品描述',
    field: 'productName',
    component: 'JInput',
  },
];

//表单数据
export const ProductFormSchema: FormSchema[] = [
  {
    label: '商品编码',
    field: 'id',
    component: 'Input',
    dynamicDisabled: true,
    show: false,
  },
  {
    label: '商品UPC条码',
    field: 'upcCode',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
  },
  {
    label: '其他条码(多个编码请用英文逗号间隔)',
    //标题长度，超过位数隐藏
    labelLength: 4,
    field: 'otherCode',
    component: 'InputTextArea',
    componentProps: {
      //可以点击清除图标删除内容
      allowClear: true,
      //是否展示字数
      showCount: false,
      //自适应内容高度，可设置为 true | false 或对象：{ minRows: 2, maxRows: 6 }
      autoSize: {
        //最小显示行数
        minRows: 2,
        //最大显示行数
        maxRows: 2,
      },
    },
  },
  {
    label: '商品描述',
    field: 'productName',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '商品描述!' }];
    },
  },
  {
    label: '一级类目',
    field: 'l1TypeCode',
    component: 'ApiSelect',
    componentProps: ({ formModel }) => {
      return {
        //multiple: 多选；不填写为单选
        //mode: 'multiple',
        //请求api,返回结果{ result: { records:[{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
        api: (params) => defHttp.get({ url: '/xl/xlProductType/loadTreeChildren', params }),
        //数值转成String
        numberToString: false,
        //标题字段
        labelField: 'title',
        //值字段
        valueField: 'key',
        //请求参数
        params: { pid: 0 },
        //返回结果字段
        resultField: 'records',
        onChange: (e, selected) => {
          //获取选中的字典值
          formModel.l1Type = selected.label;
          formModel.l2Type = '';
          formModel.l2TypeCode = '';
        },
      };
    },
    required: true,
  },
  {
    label: '一级类目',
    field: 'l1Type',
    component: 'Input',
    show: false,
  },
  {
    label: '一级类目',
    field: 'l2Type',
    component: 'Input',
    show: false,
  },
  {
    label: '二级类目',
    field: 'l2TypeCode',
    component: 'ApiSelect',
    componentProps: ({ formModel }) => {
      return {
        //multiple: 多选；不填写为单选
        //mode: 'multiple',
        //请求api,返回结果{ result: { records:[{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
        api: (params) => defHttp.get({ url: '/xl/xlProductType/loadTreeChildren', params }),
        //数值转成String
        numberToString: false,
        //标题字段
        labelField: 'title',
        //值字段
        valueField: 'key',
        //请求参数
        params: { pid: formModel.l1TypeCode },
        //返回结果字段
        resultField: 'records',
        onChange: (e, selected) => {
          //获取选中的字典值
          formModel.l2Type = selected.label;
        },
      };
    },
    ifShow: ({ values }) => {
      return !!values.l1TypeCode;
    },
    required: true,
  },
  {
    label: '商品状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'xl_product_status',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
    ifShow: false,
    defaultValue: 1,
  },
  {
    label: '商品品牌',
    field: 'brand',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'xl_product_brand,brand_name,brand_name',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
  },
  {
    label: '重量',
    field: 'weight',
    component: 'InputNumber',
    suffix: 'KG',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入重量!' }];
    },
  },
  {
    label: '箱规',
    field: 'cartonSpec',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
  },
  {
    label: '产品规格',
    field: 'productSpec',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
  },
  {
    label: '进货单价',
    field: 'purchasePrice',
    component: 'InputNumber',
    suffix: '元',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入价格!' }];
    },
  },
  {
    label: '商品主图',
    field: 'mainPic',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 1,
      bizPath: 'mainpic',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请上传商品主图!' }];
    },
  },
];



